package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysJob;
import io.mybatis.example.springboot.service.SysJobService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_job - 定时任务调度表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysJobs")
public class SysJobController {

  @Autowired
  private SysJobService sysJobService;

  @PostMapping
  public DataResponse<SysJobDO> save(@RequestBody SysJobDO sysJob) {
    return DataResponse.ok(sysJobService.save( sysJob));
  }

  @GetMapping
  public RowsResponse<SysJobDO> findList(@RequestBody SysJobDO sysJob) {
    return RowsResponse.ok(sysJobService.findList( sysJob));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysJobDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysJobService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysJobDO> update(@PathVariable("id") Long id, @RequestBody SysJobDO sysJob) {
    sysJob.setId(id);
    return DataResponse.ok(sysJobService.update( sysJob));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysJobService.deleteById(id) == 1);
  }

}
